import React from 'react'
import { HashRouter, Routes, Route, Outlet, Navigate } from 'react-router-dom'
import Login from '../views/login/Login.js'
import NewsSandBox from '../views/newsSandBox/NewsSandBox.js'
import { useSelector } from 'react-redux'

export default function IndexRouter() {
	const token = useSelector(state => state.TokenReducer.token)
	const elementMethod = () => {
		return token !== null ? <NewsSandBox /> : <Navigate to='/login' />
	}

	return (
		<HashRouter>
			<Routes>
				<Route path='/*' element={elementMethod()} />
				<Route path='/login' element={<Login />} />
			</Routes>
			<Outlet />
		</HashRouter>
	)
}